package Day9.ArraylistStudentManger;

import java.util.ArrayList;
import java.util.Scanner;

import org.junit.Test;

public class Manger {
	@Test
	public void test1() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入有几个学生：");
		int count = scanner.nextInt();
	
		ArrayList<Student> list = new ArrayList<Student>();
		
		for (int i = 0 ; i < count; i++) {
			Student student = new Student();
			System.out.println("请输入学生的id:");
			student.setId(scanner.nextInt());
			System.out.println("请输入学生的姓名:");
			student.setName(scanner.next());
			System.out.println("请输入学生的年龄:");
			student.setAge(scanner.nextInt());
			System.out.println("请输入学生的班级名称:");
			student.setClassName(scanner.next());
			
			list.add(student);
		}
		
		for (Student student : list) {
			System.out.println(student.toString());
		}
		int type = 1;
		while(type != 0) {
		System.out.println("----------------");
		System.out.println("按学生id查询输入 1");
		System.out.println("按学生name查询输入 2");
		System.out.println("按学生age查询输入 3");
		System.out.println("按学生className查询输入 4");
		System.out.println("退出查询  0");
		System.out.println("----------------");

		boolean isHave = false;
	
			type = scanner.nextInt();
			switch (type) {
			case 1:	
				System.out.println("请输入学生的id：");
				int id = scanner.nextInt();
				for (int i = 0 ; i < list.size(); i++ ) {
					Student student = list.get(i);
					if (student.getId() == id) {
						System.out.println(student.toString());
						isHave = true;
						break;
					}				
				}	
				if (isHave == false) {
					System.out.println("查无此人");
				}
				
				break;
				
			case 2:	
				System.out.println("请输入学生的name：");
				String name = scanner.next();
				for (int i = 0 ; i < list.size(); i++ ) {
					Student student = list.get(i);
					if (student.getName().equals(name)) {
						System.out.println(student.toString());	
						isHave = true;
					}
				}	
				if (isHave == false) {
					System.out.println("查无此人");
				}
				break;
				
			case 3:	
				System.out.println("请输入学生的age：");
				int age = scanner.nextInt();
				for (int i = 0 ; i < list.size(); i++ ) {
					Student student = list.get(i);
					if (student.getAge() == age) {
						System.out.println(student.toString());
						isHave = true;
					}					
				}				
				if (isHave == false) {
					System.out.println("查无此人");
				}
				break;
				
			case 4:	
				System.out.println("请输入学生的className：");
				String className = scanner.next();
				for (int i = 0 ; i < list.size(); i++ ) {
					Student student = list.get(i);
					if (student.getClassName().equals(className)) {
						System.out.println(student.toString());
						isHave = true;
					}
				}				
				if (isHave == false) {
					System.out.println("查无此人");
				}
				break;

			default:
				break;
			}
			
			
			
		}
		
		
	}
}
